package com.carboncntr.struts.action;

import java.util.List;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;

import org.apache.struts.action.ActionForm;
import org.apache.struts.action.ActionForward;
import org.apache.struts.action.ActionMapping;
import org.apache.struts.actions.DispatchAction;

import com.carboncntr.helper.HistoryHelper;
import com.carboncntr.struts.form.HistoryForm;
import com.carboncntr.tables.Customer;

public class HistoryAction extends DispatchAction {

	public ActionForward init(ActionMapping mapping, ActionForm form, HttpServletRequest request, HttpServletResponse response) {
		HttpSession session = (HttpSession)request.getSession();
		Customer c =(Customer)session.getAttribute("Customer");
		HistoryForm histForm = (HistoryForm)form;
		if(c != null) {
			double carbonBal = HistoryHelper.getCarbonBalance(c.getCustomerId());
			List historyList=HistoryHelper.listHistory(c.getCustomerId());
			histForm.setCarbonBalance(carbonBal);
			histForm.setHistoryList(historyList);
		}
		return mapping.findForward("begin");
	}
		
	
}
